package com.example.demo.thread;

import javafx.concurrent.Task;

import java.util.concurrent.*;

public class Demo2 {

    public static class Task implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            // 模拟计算需要一秒
            Thread.sleep(1000);
            return 2;
        }
    }

    public static void main(String[] args)  throws Exception  {
        /*ExecutorService executorService = Executors.newCachedThreadPool();

        Task task = new Task();

        Future<Integer> future = executorService.submit(task);
        System.out.println(future.get());*/

        ExecutorService executorService = Executors.newSingleThreadExecutor();

        Task task = new Task();

        FutureTask<Integer> futureTask = new FutureTask<>(task);

        executorService.submit(futureTask);


    }
}
